package com.cake.liulanxiangzhu.controller;

import com.cake.liulanxiangzhu.pojo.entity.OmsOrderItem;
import com.cake.liulanxiangzhu.pojo.dto.OmsOrderItemDTO;
import com.cake.liulanxiangzhu.pojo.dto.OmsOrderItemUpdateDTO;
import com.cake.liulanxiangzhu.pojo.vo.OmsOrderItemVO;
import com.cake.liulanxiangzhu.service.OmsOrderItemService;
import com.cake.liulanxiangzhu.web.JsonPage;
import com.cake.liulanxiangzhu.web.JsonResult;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.github.pagehelper.PageHelper;
import org.springframework.validation.annotation.Validated;
import javax.validation.Valid;

/**
 * 订单商品信息表(OmsOrderItem)表控制层
 *
 * @author dinghao
 * @since 2023-02-23 14:55:08
 */
@RestController
@RequestMapping("/omsOrderItem")
@Validated
public class OmsOrderItemController {
    /**
     * 服务对象
     */
    @Autowired
    private OmsOrderItemService omsOrderItemService;

    /**
     * 分页查询
     *
     * @param omsOrderItem 筛选条件
     * @return 查询结果
     */
    @GetMapping("/queryOmsOrderItemListPaging")
    public JsonResult<JsonPage<OmsOrderItemVO>> queryByPage(OmsOrderItem omsOrderItem, Integer page, Integer pageSize) {
        return JsonResult.ok(this.omsOrderItemService.queryByPage(omsOrderItem, page, pageSize));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/queryOmsOrderItemById")
    public JsonResult<OmsOrderItemVO> queryById(String id) {
        return JsonResult.ok(this.omsOrderItemService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param omsOrderItemDto 实体
     * @return 新增结果
     */
    @PostMapping("/insertOmsOrderItem")
    public JsonResult<Void> add(@Valid OmsOrderItemDTO omsOrderItemDto) {
        this.omsOrderItemService.insert(omsOrderItemDto);
        return JsonResult.ok();
    }

    /**
     * 编辑数据
     *
     * @param omsOrderItemUpdateDto 实体
     * @return 编辑结果
     */
    @PostMapping("/updateOmsOrderItem")
    public JsonResult<Void> edit(OmsOrderItemUpdateDTO omsOrderItemUpdateDto) {
        this.omsOrderItemService.update(omsOrderItemUpdateDto);
        return JsonResult.ok();
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @PostMapping("/deleteOmsOrderItem")
    public JsonResult<Void> deleteById(String id) {
       this.omsOrderItemService.deleteById(id);
       return JsonResult.ok();
    }

}

